
const defaultState = {
    selection: {
        count: 0,

        // 选中内容
        text: '',

        // 选中字符数
        wordCount: 0,

        // 选中行数
        lineCount: 0,

        start: {
            row: 0,
            column: 0
        },

        end: {
            row: 0,
            column: 0
        }
    },

    // 当前光标位置
    cursor: {
        row: 0,
        column: 0
    }
};

/**
 * 更新编辑器选中状态
 * @type {String}
 */
export const UPDATE_SELECTION = 'UPDATE_SELECTION';

/**
 * 更新编辑器光标状态 
 * @type {String}
 */
export const UPDATE_CURSOR = 'UPDATE_CURSOR';

/**
 * 编辑器状态
 * @param {Object} state
 * @param {Object} action
 */
export default function editorStatusReducer(state = defaultState, action) {
    switch (action.type) {
        case UPDATE_SELECTION:
            return {
                ...state,
                selection: {
                    ...state.selection,
                    ...action.payload
                }
            };
        case UPDATE_CURSOR:
            return {
                ...state,
                cursor: action.payload
            };
        default:
            return state;
    }
}